#include "stm8l15x.h"
#include "hc595.h"







#define		_SPI_CLK	((( strBit81 *)(&GPIOA->ODR))->Bit2)
#define		_SPI_DO		((( strBit81 *)(&GPIOA->ODR))->Bit3)
#define		_CS595		((( strBit81 *)(&GPIOG->ODR))->Bit5)
unsigned char cIoState;

/*
@inline void
refresh_io (void)
{

  GPIOA->CR1 |= 0b00001100;
  GPIOA->DDR |= 0b00001100;
  GPIOA->ODR &= 0b11110011;

  GPIOG->CR1 |= 0b00100000;
  GPIOG->DDR |= 0b00100000;
  GPIOG->ODR |= 0b00100000;
}*/

@inline void
refresh_io (void)
{ 
 
  GPIOA->CR1 |= 0b00001100;
  GPIOA->DDR |= 0b00001100;
  GPIOA->ODR &= 0b11110011;

  GPIOG->CR1 |= 0b00100000;
  GPIOG->DDR |= 0b00100000;
  GPIOG->ODR |= 0b00100000;
}


void
refresh_595 (void)
{

  unsigned char i = 8;
  unsigned char j = cIoState;
 
	
  refresh_io ();

 _asm ("nop"); 

  do
    {

   _SPI_CLK = 0;
			_SPI_DO = (*((strBit81 *)&j)).Bit7 ;
 
      j *= 2;

      _SPI_CLK = 1;
      _asm ("nop");
   }
  while (--i);
 _CS595 = 0;

  _asm ("nop");
  _CS595 = 1;
}
